package com.zhss.dfs.namenode.server;

/**
 * NameNode核心启动类
 */
public class NameNode {
    /**
     * nameNode是否在运行
     */
    private volatile Boolean shouldRun;
    /**
     * 负责管理元数据的核心组件：管理文件目录树，支持权限设置
     */
    private FSNamesystem namesystem;

    /**
     * 负责管理集群中所有的dataNode的组件
     */
    private DataNodeManager dataNodeManager;
    /**
     * NameNode对外提供rpc接口的server，可以响应请求
     */
    private NameNodeRpcServer nameNodeRpcServer;


    public NameNode(){
        this.shouldRun = true;
    }

    /**
     * 初始化nameNode
     */
    private  void initialize(){
        this.namesystem = new FSNamesystem();
        this.dataNodeManager = new DataNodeManager();
        this.nameNodeRpcServer = new NameNodeRpcServer(this.namesystem,this.dataNodeManager);
        nameNodeRpcServer.start();
    }

    private  void run(){
        try {
            while(shouldRun){

                Thread.sleep(10000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void shutdown(){
        this.shouldRun = false;
    }

    public static void main(String[] args) throws Exception{
        NameNode nameNode = new NameNode();
        nameNode.initialize();
        nameNode.run();
    }

}
